package com.star.service.impl;

import com.star.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Author star
 * @Date 2023/4/17 9:27
 * @PackageName:com.star.service.impl
 * @ClassName: SendMailServiceImpl
 * @Description: TODO
 * @Version 1.0
 */
@Service
public class SendMailServiceImpl implements SendMailService {

    @Autowired
    private JavaMailSender javaMailSender;


    //发送人
    private String FROM = "2835178258@qq.com";

    //接收人
    private String TO = "";

    //标题
    private String SUBJECT = "验证码";

    //主题
    private String CONTENT = "";


    /**
     * 发送邮箱验证码
     *
     * @param autoCode
     * @param email
     */
    @Override
    public void sendmail(Integer autoCode, String email) {
        TO = email;
        CONTENT = "【人人车商城】验证码：" + autoCode + "用于登录身份验证，3分钟内有效，请勿泄露和转发。如非本人操作，请忽略此邮件。";
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(FROM);
        simpleMailMessage.setTo(TO);
        simpleMailMessage.setSubject(SUBJECT);
        simpleMailMessage.setText(CONTENT);
        //发送邮件
        javaMailSender.send(simpleMailMessage);
    }


    /**
     * 给自己发送提示邮件
     */
    @Override
    public void sendMail(String message) {
        TO = "2835178258@qq.com";
        CONTENT = message;
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(FROM);
        simpleMailMessage.setTo(TO);
        simpleMailMessage.setSubject(SUBJECT);
        simpleMailMessage.setText(CONTENT);
        //发送邮件
        javaMailSender.send(simpleMailMessage);
    }


}
